<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title><?php echo $title; ?></title>
    <base href="<?php echo base_url(); ?>">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/layout.css">
    <link rel="stylesheet" href="layui/css/layui.css">
</head>

<body class="iframe-body">
<!--{ 新增游戏 -->
<div class="row">
    <div class="col-sm-12">
        <form class="form-horizontal" id="add_form" role="form" method="post" enctype="multipart/form-data" action="">
                <div class="form-group">
                    <label class="col-sm-3 control-label">
                        <samp class="f-samp">*</samp>VR名称</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" id="banner" name="banner" value="<?php echo $info['banner'];?>" required>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">VR图</label>
                    <div class="col-sm-9">
                        <img class="fn-mb-15" id="upload_img" src="<?php echo $info['banner_pic']?>" width="100" style="display:block;" value=""/>
                        <button type="button" class="layui-btn" id="upload" data-name="userfile">
                          <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                    </div>
                </div>                
                <div class="form-group">
                    <label class="col-sm-3 control-label labell">状态</label>
                    <div class="col-sm-9" style="padding-top:7px">
                        下架
                        <input name="status" type="radio" value="0" <?php if($info['status']==0) echo 'checked';?>/>&nbsp;&nbsp;&nbsp; 上架
                        <input name="status" type="radio" value="1" <?php if($info['status']==1) echo 'checked';?>/>
                    </div>
                </div>
                <input type="hidden" name="banner_id" value="<?php echo $info['id'];?>" />
                <input id="upload_url" type="hidden" name="banner_pic" value="<?php echo $info['banner_pic']?>">
                <div class="form-group">
                <input type="submit" id="fileSubmit" name="Submit" class="btn btn-success col-sm-1 col-sm-offset-5" value="提交" />
                </div>
            </form>
    </div>
</div>
<!--/ 新增用户 }-->

<script src="/js/plugins/jquery.js"></script>
<script src="/js/plugins/layer/layer.js"></script>
<!-- <script src="/js/common.js"></script> -->
<script src="/layui/layui.js"></script>
<script>
    $(function () {

        layui.use('upload', function(){
          var upload = layui.upload;
           
          //执行实例
          var uploadInst = upload.render({
            elem: '#upload' //绑定元素
            ,url: 'banner/do_upload' //上传接口
            ,data:{name:function(){
                            return $('#upload').data('name');
            }}
            ,done: function(res){
                var banner_name = res.data.upload_data.file_name;
                console.log(res.data.upload_data.file_name);
                var upload_url = '/uploads/banner/'+banner_name;
                $('#upload_url').val(upload_url);
                $('#upload_img').css('display','block').attr('src',upload_url);
                layer.msg('上传完成');
                console.log(res);
              //上传完毕回调
            }
            ,error: function(){
              //请求异常回调
            }
          });
        });

        //父级地址
        var parentURL = window.parent.location.href;
        

        $('#add_form').submit(function(){   
            if($('#banner_url').val() == ''){
                layer.msg('请上传banner图片',{time:1000});
                return false;
            } 
            var datas = $('#add_form').serialize();
            $.ajax({
                url:"banner/banneredit",
                type:"post",
                data: datas,
                dataType:"json",
                success: function (data) {
                    if (data.ack == true) {
                        layer.msg(data.msg, {time: 1200}, function () {
                            //成功后重新刷新父级页面
                            window.parent.location.reload(parentURL);
                        });
                    }else{
                        layer.msg(data.msg, {time: 1200});
                    }
                }
            });
            return false;
        }); 
    });
</script>
</body>
</html>
